(function () {
    var ResultPVPList = (function (_super) {
        var CAMP = {
            "red" : 1,
            "blue" : 0
        };
        var RESULT_STATE = {
            "win" : 2,
            "lose" : 0,
            "draw" : 1,
        };

        function PVPList(index, data) {
            PVPList.super(this);

            this.index = null;

            this.init(index, data);
        }
        Laya.class(PVPList, "", _super);
        var _proto = PVPList.prototype;

        _proto.init = function (index, data) {
            this.setup(index);
            this.update(data);
        }
        _proto.setup = function (index) {
            this.centerX = 0;
            this.y = index * 78 + 80 - 50;
            this.alpha = 0;

            this.index = index;
        }
        _proto.update = function (data) {
            console.log(data);
            this.listBG.index = CAMP[data.camp];
            this.state.index = RESULT_STATE[data.res];
            this.avatar.skin = data.avatar == "" ? USER_DEFAULT_AVATAR : data.avatar;
            this.userName.text = data.userName;
            this.killNum.text = data.killNum;
            this.helpNum.text = data.helpNum;
            this.coin.text = data.money;
            this.medal.text = data.medal;
            this.exp.text = data.exp + "/" + data.nextExp;

            var progress = data.exp / data.nextExp;
            if(data.exp == 0){
                this.expNum.visible = false;
            }else{
                this.expNum.visible = true;
                this.expNum.width = progress * 220;
            }
        }
        _proto.enter = function () {
            Laya.Tween.to(this, {y : this.y + 50, alpha : 1}, 500, null, null, (this.index + 1) * 300);
        }

        return PVPList;
    })(ui.Result.PVPListUI);

    (function (_super) {
        function ResultPVP(data) {
            ResultPVP.super(this);

            this.headerUI = null;
            this.listUI = [];

            this.init(data);
        }
        Laya.class(ResultPVP, "Com.Result.PVP", _super);
        var _proto = ResultPVP.prototype;
        _proto.destroy = function () {
            _super.prototype.destroy.call(this, true);

            this.headerUI = null;
            this.listUI = null;
        }

        _proto.init = function (data) {
            this.size(1314, 390);
            this.pos(GAME_CONFIG.WIDTH / 2 - this.width / 2, Laya.stage.height / 2 - 165);

            var headerUI = new ui.Result.PVPHeaderUI();
                headerUI.alpha = 0;
                headerUI.centerX = 0;
                headerUI.y = -30;

            this.headerUI = headerUI;
            this.addChild(headerUI);

            for(var i = 0; i < data.roles.length; i ++){
                var list = new ResultPVPList(i, data.roles[i]);
                this.listUI.push(list);
                this.addChild(list);
            }
        }
        _proto.enter = function () {
            Laya.Tween.to(this.headerUI, {y : 0, alpha : 1}, 500);

            for(var i in this.listUI){
                this.listUI[i].enter();
            }
        }
        _proto.resize = function (height) {
            this.y = height / 2 - 165;
        }
    })(Laya.Sprite);
})();